package org.stock.agent.tools;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.stock.agent.client.StockClient;
import org.stock.agent.config.ApiKeyConfig;

@Component
@Slf4j
public class StockTools {
    
    @Autowired
    private StockClient stockClient;
    
    @Autowired
    private ApiKeyConfig apiKeyConfig;


    @Tool(description = "获取最新分时交易数据")
    public String getLatestTransaction(String stockCode) {
        String result = stockClient.getLatestTransaction(stockCode, apiKeyConfig.getKey());
        log.info("getLatestTransaction result for stockCode {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取行情指标数据")
    public String getIndicators(String stockCode) {
        String result = stockClient.getIndicators(stockCode, apiKeyConfig.getKey());
        log.info("获取行情指标数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取股票基础信息")
    public String getStockBasicInfo(String stockCode) {
        String result = stockClient.getStockBasicInfo(stockCode, apiKeyConfig.getKey());
        log.info("获取股票基础信息 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取历史分时MACD数据")
    public String getHistoricalMACD(String stockCode) {
        String result = stockClient.getHistoricalMACD(stockCode, apiKeyConfig.getKey());
        log.info("获取历史分时MACD数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取历史分时MA数据")
    public String getHistoricalMA(String stockCode) {
        String result = stockClient.getHistoricalMA(stockCode, apiKeyConfig.getKey());
        log.info("获取历史分时MA数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取历史分时BOLL数据")
    public String getHistoricalBOLL(String stockCode) {
        String result = stockClient.getHistoricalBOLL(stockCode, apiKeyConfig.getKey());
        log.info("获取历史分时BOLL数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取历史分时KDJ数据")
    public String getHistoricalKDJ(String stockCode) {
        String result = stockClient.getHistoricalKDJ(stockCode, apiKeyConfig.getKey());
        log.info("获取历史分时KDJ数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取单股实时交易数据")
    public String getSingleStockRealTime(String stockCode) {
        String result = stockClient.getSingleStockRealTime(stockCode, apiKeyConfig.getKey());
        log.info("获取单股实时交易数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取券商数据源实时交易数据")
    public String getBrokerRealTime(String stockCode) {
        String result = stockClient.getBrokerRealTime(stockCode, apiKeyConfig.getKey());
        log.info("获取券商数据源实时交易数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取资金流向数据")
    public String getCapitalFlow(String stockCode) {
        String result = stockClient.getCapitalFlow(stockCode, apiKeyConfig.getKey());
        log.info("获取资金流向数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取资产负债表数据")
    public String getBalanceSheet(String stockCode) {
        String result = stockClient.getBalanceSheet(stockCode, apiKeyConfig.getKey());
        log.info("获取资产负债表数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取利润表数据")
    public String getIncomeStatement(String stockCode) {
        String result = stockClient.getIncomeStatement(stockCode, apiKeyConfig.getKey());
        log.info("获取利润表数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取现金流量表数据")
    public String getCashFlowStatement(String stockCode) {
        String result = stockClient.getCashFlowStatement(stockCode, apiKeyConfig.getKey());
        log.info("获取现金流量表数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取财务主要指标数据")
    public String getFinancialMainIndex(String stockCode) {
        String result = stockClient.getFinancialMainIndex(stockCode, apiKeyConfig.getKey());
        log.info("获取财务主要指标数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取公司股本表数据")
    public String getCompanyCapital(String stockCode) {
        String result = stockClient.getCompanyCapital(stockCode, apiKeyConfig.getKey());
        log.info("获取公司股本表数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取公司十大股东数据")
    public String getTopShareholders(String stockCode) {
        String result = stockClient.getTopShareholders(stockCode, apiKeyConfig.getKey());
        log.info("获取公司十大股东数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取公司十大流通股东数据")
    public String getTopCirculatingShareholders(String stockCode) {
        String result = stockClient.getTopCirculatingShareholders(stockCode, apiKeyConfig.getKey());
        log.info("获取公司十大流通股东数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取公司股东数数据")
    public String getShareholderNumbers(String stockCode) {
        String result = stockClient.getShareholderNumbers(stockCode, apiKeyConfig.getKey());
        log.info("获取公司股东数数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取近年分红数据")
    public String getRecentDividends(String stockCode) {
        String result = stockClient.getRecentDividends(stockCode, apiKeyConfig.getKey());
        log.info("获取近年分红数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取近年增发数据")
    public String getRecentOfferings(String stockCode) {
        String result = stockClient.getRecentOfferings(stockCode, apiKeyConfig.getKey());
        log.info("获取近年增发数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取解禁限售数据")
    public String getRestrictedStockUnlock(String stockCode) {
        String result = stockClient.getRestrictedStockUnlock(stockCode, apiKeyConfig.getKey());
        log.info("获取解禁限售数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取近一年各季度利润数据")
    public String getQuarterlyProfit(String stockCode) {
        String result = stockClient.getQuarterlyProfit(stockCode, apiKeyConfig.getKey());
        log.info("获取近一年各季度利润数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取近一年各季度现金流数据")
    public String getQuarterlyCashFlow(String stockCode) {
        String result = stockClient.getQuarterlyCashFlow(stockCode, apiKeyConfig.getKey());
        log.info("获取近一年各季度现金流数据{}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取近年业绩预告数据")
    public String getPerformanceForecast(String stockCode) {
        String result = stockClient.getPerformanceForecast(stockCode, apiKeyConfig.getKey());
        log.info("获取近年业绩预告数据 {}: {}", stockCode, result);
        return result;
    }

    @Tool(description = "获取财务指标数据")
    public String getFinancialIndicators(String stockCode) {
        String result = stockClient.getFinancialIndicators(stockCode, apiKeyConfig.getKey());
        log.info("获取财务指标数据 {}: {}", stockCode, result);
        return result;
    }
}